package com.spark.demonetty.netty_demo.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * @author fuqiang
 * @Description protoBuf deme代码
 * @Date 2020/10/22
 */
public class SubReqServer extends AbstractServer{

    @Override
    public ServerBootstrap getDefaultBootstrap() {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup,workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG,1024)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
//                        ch.pipeline().addLast(new ProtobufDecoder())
                    }
                });
        return b;
    }

    public static void main(String[] args) {
        int port = 10010;
        if(args != null && args.length > 0){
            port = Integer.valueOf(args[0]);
        }
        new SubReqServer().bind(port);
    }

}
